/**
 * Created by Administrator on 2017/4/17 0017.
 */
import React from "react";
import { Modal,message } from 'antd';
import Relay from "react-relay";
import ReqAdditionalMutation from "../mutation/ReqAdditionalMutation"

export default class Modal_PayFor extends React.Component{
    constructor(props){
        super(props);
        this.state={
            visible:false,
            oid:'',
            account:'',
            inputaccount:'',
            textareadesp:'',
        }
    }

    componentWillMount(){

    }
    _onCancel(){
        this.setState({
            visible:false
        });
    }
    changeAccount(e){
        let text = e.target.value;
        let regular = /^[0-9,'.']*$/;
        if(!regular.test(text)){
            return
        }
        this.setState({
            inputaccount:text
        });
    }

    changeDesp(e){
        let text = e.target.value;
        this.setState({
            textareadesp:text
        });
    }

    modalAfterClose(){
        this.setState({
            inputaccount:'',
            textareadesp:'',

        });
    }

    _SureFor(){
        if(this.state.inputaccount==''){
            message.info('请填写金额');
            return
        }
        if(this.state.textareadesp==''){
            message.info('请填写说明');
            return
        }
        let textareadesp = this.state.textareadesp.replace(/\s/g,'');
        if(textareadesp.length==0){
            message.info('说明不能为空');
            return
        }

        Relay.Store.commitUpdate(
            new ReqAdditionalMutation({
                description:this.state.textareadesp,
                money:this.state.account,
                orderId:this.state.oid,
                uid:this.props.uid,
                actualMoney:this.state.inputaccount

            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorCode = response.reqAdditional.reqAdditional.errorCode;
                    if(errorCode==0){
                        message.success('申请成功');
                        this.setState({
                            visible:false
                        });
                    }
                }
            }
        )

    }




    addSupplementPart(){
        if(this.state.fullin){
            return(
                <div>

                </div>
            );
        }else{
            return(
                <div>
                    <div className={'order_orderpurch_modal_payfor_oiddiv'}>实际金额：{this.state.inputaccount}</div>
                    <div className={'order_orderpurch_modal_payfor_oiddiv'}>补充说明：{this.state.textareadesp}</div>
                    <div className={'order_orderpurch_modal_payfor_divforbuttonagree'} onClick={this._Agree.bind(this)}>同意</div>
                    <div className={'order_orderpurch_modal_payfor_divforbuttonagreenone'} onClick={this._Disagree.bind(this)}>不同意</div>

                </div>
            );
        }

    }


    render(){
        return (
            <Modal title={'合同补充'} maskClosable={true} footer={null} visible={this.state.visible} onCancel={this._onCancel.bind(this)}
                   afterClose={this.modalAfterClose.bind(this)}>
                <div className={'order_orderpurch_modal_payfor_oiddiv'}>订单编号：{this.state.oid}</div>
                <div className={'order_orderpurch_modal_payfor_oiddiv'}>订单金额：￥{this.state.account/100}</div>
                <div className={'order_orderpurch_modal_payfor_oiddiv'}>实际金额：
                    <input className={'order_orderpurch_modal_payfor_oidinput'} ref={'accountinput'} onChange={this.changeAccount.bind(this)} value={this.state.inputaccount}/>
                </div>
                <div className={'order_orderpurch_modal_payfor_oiddiv'}>
                    <span className="order_orderpurch_modal_payfor_oidspan">补充说明：</span>
                    <textarea className={'order_orderpurch_modal_payfor_textarea'} ref={'textarea'} value={this.state.textareadesp} onChange={this.changeDesp.bind(this)}/>
                </div>
                <div className={'order_orderpurch_modal_payfor_divforbutton'} onClick={this._SureFor.bind(this)}>确定</div>
            </Modal>
        )
    }
}
